﻿//---------------------------------------------------------------------------
// 
// File: HtmlTokenType.cs
//
// Copyright (C) Microsoft Corporation.  All rights reserved.
//
// Description: Definition of token types supported by HtmlLexicalAnalyzer
//
//---------------------------------------------------------------------------

namespace HTMLConverter.XamlConverters
{
    // DependencyProperty
    // TextElement
    using System.Xml.Linq;
    using HTMLConverter.Xml;

    /// <summary>
    /// HtmlToXamlConverter is a static class that takes an HTML string
    /// and converts it into XAML
    /// </summary>
    internal class ImageConverter : IConverter
    {
        public Tag Type
        {
            get { return Tag.Image; }
        }

        public XmlElement Convert(XNode htmlNode)
        {
            //  Implement images

            XmlElement container = new XmlElement(HtmlConverter.Xaml_InlineUIContainer, HtmlConverter.Xaml_Namespace);
            if (htmlNode is XmlElement)
            {
                XmlElement htmlElement = htmlNode as XmlElement;

                string src = htmlElement.GetAttribute("src");
                if (string.IsNullOrEmpty(src) == false)
                {
                    XmlElement image = new XmlElement(HtmlConverter.Xaml_Image, HtmlConverter.Xaml_Namespace);
                    image.SetAttribute(HtmlConverter.Xaml_Image_Source, src);
                    container.AppendChild(image);
                }
            }

            return container;
        }
    }
}
